package com.wondertek.mam.tag.wordSource.impl;

import com.wondertek.mam.tag.tagrep.TagRep;
import com.wondertek.mam.tag.wordSource.WordSource;
import com.wondertek.mam.tag.wordSource.bean.NetHotWord;

/**
 * 词源
 * Created by wangdongxu on 2017-09-18 上午 9:30:36.
 */
public abstract class WordSourceAbstract implements WordSource {

    private TagRep tagRep;
    WordSourceAbstract(TagRep tagRep){
        this.tagRep = tagRep;
    }

    /**
     * 保存热词
     * @param netHotWord 热词
     */
    @Override
    public void saveHotWords(NetHotWord netHotWord){
        this.tagRep.save(netHotWord);
    }

    /**
     * 获取和保存
     */
    @Override
    public void getAndSaveHotWords() {
        getUrls()
            .parallelStream()
            .forEach(url -> {
                NetHotWord hotWordsByUrl = getHotWordsByUrl(url);
                if (hotWordsByUrl==null){
                    return;
                }
                saveHotWords(hotWordsByUrl);
        });
    }
}
